package service.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import domain.vo.queryObject;
import module.HousePhoto;
import module.Houses;
import module.Logs;
import module.Phones;
import service.housesService;

/**
 * 
 * @ClassName: HousesServiceImpl
 * @Description: 房屋服务层实现类
 * @author chenchao
 * @date 2013-10-31 上午06:52:32
 * 
 */
public class HousesServiceImpl extends housesService {
	private Logger logger = Logger.getLogger(HousesServiceImpl.class.getName());

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#countByQueryObject(domain.vo.queryObject)
	 */
	public int countByQueryObject(queryObject queryObject) throws SQLException {
		// TODO Auto-generated method stub
		return housesDAO.countByQueryObject(queryObject);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#getObjectByQueryObject(domain.vo.queryObject)
	 */
	public List<Houses> getObjectByQueryObject(queryObject queryObject)
			throws SQLException {
		// TODO Auto-generated method stub
		return housesDAO.getObjectByQueryObject(queryObject);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#deleteT(java.lang.Object)
	 */
	public void deleteT(Houses t) throws SQLException {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#getAll()
	 */
	public List<Houses> getAll() throws SQLException {
		// TODO Auto-generated method stub
		return housesDAO.getAll();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#getById(java.lang.String)
	 */
	public Houses getById(String id) throws SQLException {
		// TODO Auto-generated method stub
		return housesDAO.getById(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#insertObject(java.lang.Object)
	 */
	public void insertObject(Houses t) throws SQLException {
		try {
			sqlMapClient.startTransaction();
			housesDAO.insertT(t);
			sqlMapClient.startBatch();
			logger.debug("保存图片");
			for (HousePhoto  p : t.getHousePhotos()) {
				p.setHouseid(t.getHousesId());
				hpDAO.insertT(p);
			}
			sqlMapClient.executeBatch();
			sqlMapClient.commitTransaction();
		} finally {
			sqlMapClient.endTransaction();
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see service.basicService#updateObject(java.lang.Object)
	 */
	public void updateObject(Houses t) throws SQLException {
		try {
			sqlMapClient.startTransaction();
			housesDAO.updateT(t);
			sqlMapClient.startBatch();
			logger.debug("保存修改日志");
			for (Logs log : t.getHouseLogs()) {
				log.setFkid(t.getHousesId());
				logsDAO.insertT(log);
			}
			logger.debug("保存图片");
			for (HousePhoto  p : t.getHousePhotos()) {
				p.setHouseid(t.getHousesId());
				hpDAO.insertT(p);
			}
			sqlMapClient.executeBatch();
			sqlMapClient.commitTransaction();
		} finally {
			sqlMapClient.endTransaction();
		}
	}

}
